// JavaScript Document
function tracker()
{
var fullRef = document.referrer;  //get referrer
var count = 0;
var pos = 0;
while (count < 3)  //get third instance of "/" in referrer which is "peek"
{
var peek = fullRef.indexOf("/", pos);
pos = pos + peek;
//alert(pos);
count++;
}

var partRef = fullRef.substring(peek);  //extract string of referrer after host name
//alert("partRef= " + unescape(partRef));
var partRef = unescape(partRef);  //decode the referrer fragment
 
//alert("ref= " + unescape(partRef));

var allCookies = document.cookie;  //read all cookies
var startPos = allCookies.indexOf("Refcookie=");  //find start index of Refcookie
//alert("startPos= " + startPos);

if (startPos != -1){   //if refCookie exists process it to add new referrer
var startPos = startPos + 10; //set beginning of RefCookie
var endPos = allCookies.indexOf(";", startPos);  //find end of RefCookie
if (endPos == -1) endPos = allCookies.length;
//alert("endPos= " + endPos);//make sure we have the an ending position
var cookieValue = allCookies.substring(startPos, endPos);  //grab Refcookie value
//alert("cookieValue= " + unescape(cookieValue));
cookieValue = unescape(cookieValue);  //decode cookie
var myrefCookie = (cookieValue) + "$" + (partRef);  //build new cookie
//alert("myrefCookie =" + unescape(myrefCookie));
document.cookie="Refcookie=" + escape(myrefCookie) + ";path=/;domain=mayoclinic.org";
return unescape(myrefCookie);

}
else  //if no refCookie write the full referrer into the new cookie
{
document.cookie="Refcookie=" + escape(fullRef) + ";path=/;domain=mayoclinic.org";
}
startPos = "";
endPos = "";
allCookies = "";
ref = "";
cookieValue = "";
myrefCookie = "";
}

 function clearCookie(){
document.cookie="Refcookie=;path=/;domain=mayoclinic.org";
//window.status=document.cookie;
}